package lol

import (
	"gitee.com/startbbq/go-package/strval"
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
	"github.com/GoAdminGroup/go-admin/template/types"
	"github.com/GoAdminGroup/go-admin/template/types/form"
	"github.com/gogf/gf/frame/g"
)

func GetLolHeroTable(ctx *context.Context) table.Table {

	lolHero := table.NewDefaultTable(table.DefaultConfigWithDriver("mysql"))

	info := lolHero.GetInfo().HideFilterArea()

	info.AddField("Id", "id", db.Int).
		FieldFilterable().
		FieldSortable()
	info.AddField("cd", "is_cd", db.Float).
		FieldFilterable().
		FieldEditAble()
	info.AddField("物理伤害", "is_ad_hurt", db.Float).
		FieldFilterable().
		FieldEditAble()
	info.AddField("物坑", "is_ad_resistance", db.Float).
		FieldFilterable().
		FieldEditAble()
	info.AddField("魔法伤害", "is_ap_hurt", db.Float).
		FieldFilterable().
		FieldEditAble()
	info.AddField("魔坑", "is_ap_resistance", db.Float).
		FieldFilterable().
		FieldEditAble()
	info.AddField("韧性", "is_toughness", db.Float).
		FieldFilterable().
		FieldEditAble()
	info.AddField("射程", "is_range", db.Int).
		FieldFilterable().
		FieldSortable().
		FieldEditAble()
	info.AddField("英雄名称", "hero_name", db.Varchar).
		FieldFilterable().
		FieldEditAble()
	info.AddField("英雄搜索关键字", "hero_keyword", db.Varchar).
		FieldFilterable().
		FieldEditAble()
	info.AddField("当前游戏版本", "is_version", db.Varchar).
		FieldFilterable().
		FieldEditAble()
	info.AddField("修改数据时间", "edittime", db.Timestamp).
		FieldFilterable(types.FilterType{FormType: form.DatetimeRange}).
		FieldSortable()
	info.AddField("位置id", "class_id", db.Varchar).
		FieldFilterable()
	info.AddField("战略id", "brand_id", db.Varchar).
		FieldFilterable()
	info.AddField("归档id", "archiving_id", db.Varchar).
		FieldFilterable()

	info.SetTable("lol_hero").SetTitle("英雄属性列表表格").SetDescription("英雄属性数据详情表格")

	formList := lolHero.GetForm()
	formList.AddField("Id", "id", db.Int, form.Number).
		FieldDisableWhenCreate().
		FieldDisableWhenUpdate()
	formList.AddField("cd", "is_cd", db.Float, form.Currency).
		FieldDefault("0")
	formList.AddField("物理伤害", "is_ad_hurt", db.Float, form.Currency).
		FieldDefault("0")
	formList.AddField("物坑", "is_ad_resistance", db.Float, form.Currency).
		FieldDefault("0")
	formList.AddField("魔法伤害", "is_ap_hurt", db.Float, form.Currency).
		FieldDefault("0")
	formList.AddField("魔坑", "is_ap_resistance", db.Float, form.Currency).
		FieldDefault("0")
	formList.AddField("韧性", "is_toughness", db.Float, form.Currency).
		FieldDefault("0")
	formList.AddField("射程", "is_range", db.Int, form.Number).
		FieldDefault("0")
	formList.AddField("英雄名称", "hero_name", db.Varchar, form.Text)
	formList.AddField("英雄搜索关键字", "hero_keyword", db.Varchar, form.Text)
	formList.AddField("当前游戏版本", "is_version", db.Varchar, form.Text)
	formList.AddField("修改数据时间", "edittime", db.Timestamp, form.Datetime).
		FieldDisableWhenCreate().
		FieldDisableWhenUpdate().
		FieldHide()

	lol_hero_class, _ := g.DB().Model("lol_hero_class").All()
	var class_st types.FieldOptions
	for _, v := range lol_hero_class {
		class_st = append(class_st, types.FieldOption{
			Text:  strval.Strval(v["title"]),
			Value: strval.Strval(v["is_value"]),
		})
	}
	formList.AddField("位置id", "class_id", db.Varchar, form.Select).
		// 多选的选项，text代表显示内容，value代表对应值
		FieldOptions(class_st)

	lol_hero_brand, _ := g.DB().Model("lol_hero_brand").All()
	var brand_st types.FieldOptions
	for _, v := range lol_hero_brand {
		brand_st = append(brand_st, types.FieldOption{
			Text:  strval.Strval(v["title"]),
			Value: strval.Strval(v["is_value"]),
		})
	}
	formList.AddField("战略id", "brand_id", db.Varchar, form.Select).
		// 多选的选项，text代表显示内容，value代表对应值
		FieldOptions(brand_st)

	lol_hero_archiving, _ := g.DB().Model("lol_hero_archiving").All()
	var archiving_st types.FieldOptions
	for _, v := range lol_hero_archiving {
		archiving_st = append(archiving_st, types.FieldOption{
			Text:  strval.Strval(v["title"]),
			Value: strval.Strval(v["is_value"]),
		})
	}
	formList.AddField("归档id", "archiving_id", db.Varchar, form.Select).
		// 多选的选项，text代表显示内容，value代表对应值
		FieldOptions(archiving_st)

	formList.SetTable("lol_hero").SetTitle("英雄属性列表表单").SetDescription("英雄属性数据详情表单")

	return lolHero
}
